/*
 * 作者:熊猫
 * 日期:2017 - 3 - 16 3 - 51 - 2
 *
 */

package net.lainiao.morethread.Chapter7.demo2;

import java.util.concurrent.Executor;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/16.
 */
public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor executor=new ThreadPoolExecutor(2,2,1, TimeUnit.SECONDS,new PriorityBlockingQueue<Runnable>());
        for (int i = 0; i < 4; i++) {
            MyPriorityTask task=new MyPriorityTask("Task "+i,i);
            executor.execute(task);
        }
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 4; i <8 ; i++) {
            MyPriorityTask task=new MyPriorityTask("Task "+i,i);
            executor.execute(task);
        }
        executor.shutdown();
        try {
            executor.awaitTermination(1,TimeUnit.DAYS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Main Over");
    }
}
